package ev;

import java.util.Random;

import TeamPursuit.MensTeamPursuit;
import TeamPursuit.SimulationResult;
import TeamPursuit.WomensTeamPursuit;

public class EA_Team_Men implements Team_Men {

	@Override
	public void emulation() {
		boolean [] strategy = {true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false};
	    int [] power = {550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550};
    	SimulationResult result = null;
        MensTeamPursuit mensTeamPursuit = new MensTeamPursuit();
        
        int times = 5000;
        double finalTime = 1000;
        int index, pValue;
        Random r = new Random();
		while(times>0){
			index = r.nextInt(power.length);
			pValue = power[index];
			power[index] = r.nextInt(1001)+200;
			//System.out.println(index+" "+power[index]);
        	try {
        		result = mensTeamPursuit.simulate(strategy, power);
			} catch (Exception e) {
				e.printStackTrace();
			}
			if(result.getProportionCompleted() < 0.9999998){
				//System.out.println(result.toString());
				power[index] = pValue;
				continue;
			}
			if(result.getFinishTime()<finalTime){
				finalTime = result.getFinishTime();
				//System.out.println(finalTime);
			}
			else{
				power[index] = pValue;
				//System.out.println(finalTime);

			}
			times--;
			System.out.println(times);
		}

		System.out.println(finalTime);
    	try {
    		result = mensTeamPursuit.simulate(strategy, power);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(result.toString());
		for(int i =0; i < strategy.length; i++){
			System.out.print(strategy[i]+" ");
		}
		System.out.println();
		for(int i =0; i < power.length; i++){
			System.out.print(power[i]+" ");
		}
	}

}